tyNamespace.TyModelLayer = cc.LayerColor.extend({
    listener: null,
    fixedPriority: 0,
    touchArea: null,
    isTouchLimit: false,

    ctor: function () {
        this._super();
        this.fixedPriority = -128;

        this.setColor(cc.color.BLACK);
        this.setOpacity(70);

        return true;
    },

    setTouchArea: function (size, position) {
        var touchArea = new cc.LayerColor();
        touchArea.setColor(cc.color.BLACK);
        touchArea.setOpacity(1);
        touchArea.changeWidthAndHeight(size.width, size.height);
        touchArea.setPosition(position.x, position.y);
        this.addChild(touchArea);

        this.touchArea = touchArea;
        this.isTouchLimit = true;
        
    },

    onEnterTransitionDidFinish: function () {
        this._super();

        var listener = cc.EventListener.create({
            event: cc.EventListener.TOUCH_ONE_BY_ONE,
            swallowTouches: true,
            onTouchBegan: function (touch, event) {
                var target = event.getCurrentTarget();
                if (target.isTouchLimit) {
                    var locationInNode = target.touchArea.convertToNodeSpace(touch.getLocation());
                    var s = target.touchArea.getContentSize();
                    var rect = cc.rect(0, 0, s.width, s.height);
                    if (!cc.rectContainsPoint(rect, locationInNode)) {
                        return false;
                    }
                }
                return true;
            }
        });
        cc.eventManager.addListener(listener, this);
        this.listener = listener;
    },

    onExitTransitionDidStart: function () {
    	this.listener && cc.eventManager.removeListener(this.listener);//cc.sys.isObjectValid(this.listener) &&
        this._super();
    }
});

tyNamespace.TyModelLayer1 = cc.LayerColor.extend({
    listener: null,
    fixedPriority: 0,
    nodes: [],

    ctor: function () {
        this._super();
        this.fixedPriority = -128;

        this.setColor(cc.color.BLACK);
        this.setOpacity(70);

        return true;
    },

    setMyNodes: function (nodes) {
        this.nodes = nodes;
        for (var a = 0; a < nodes.length; a++) {
            nodes[a].retain();
        }
    },

    getMyNodes: function () {
        return this.nodes;
    },

    onEnterTransitionDidFinish: function () {
        this._super();

        var self = this;

        var listener = cc.EventListener.create({
            event: cc.EventListener.TOUCH_ONE_BY_ONE,
            swallowTouches: true,
            onTouchBegan: function (touch, event) {
                return true;
            },
            onTouchEnded: function (touch, event) {
                if (self.getMyNodes().length) {
                    for (var a = 0; a < self.getMyNodes().length; a++) {
                        self.getMyNodes()[a].setVisible(true);
                    }
                }
                var target = event.getCurrentTarget();
                target.removeFromParent(false);
            }
        });
        cc.eventManager.addListener(listener, this);
        this.listener = listener;
    },

    onExitTransitionDidStart: function () {
//        this.listener && cc.sys.isObjectValid(this.listener) && cc.eventManager.removeListener(this.listener);
        this._super();
    }
});